'''
Created on Dec 24, 2010

@author: dexen
'''

import os
import sys

HOUDINI_BASE_FILE = os.path.join(os.getcwd(), "houdinibasefile")

def enableHouModule():
    '''Set up the environment so that "import hou" works.'''
    # Importing hou will load in Houdini's libraries and initialize Houdini.
    # In turn, Houdini will load any HDK extensions written in C++.  These
    # extensions need to link against Houdini's libraries, so we need to
    # make sure that the symbols from Houdini's libraries are visible to
    # other libraries that Houdini loads.  So, we adjust Python's dlopen
    # flags before importing hou.
    if hasattr(sys, "setdlopenflags"):
        old_dlopen_flags = sys.getdlopenflags()
        import DLFCN
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    try:
        import hou
    except ImportError:
        # Add $HFS/houdini/python2.5libs to sys.path so Python can find the
        # hou module.
        path = os.environ['HFS'] + "/houdini/python%d.%dlibs" % sys.version_info[:2]
        
        centos_path = os.environ['HFS'] + "/houdini/python2.5libs"
        centos_path2 = os.environ['HFS'] + "/python/lib"
        print path
        sys.path.append(path)
        #sys.path.append(centos_path)
        #sys.path.append(centos_path2)
        import hou
    finally:
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)
            

    
